package com.example.demo.algorithm.test;

import com.example.demo.algorithm.sort.Insertion;
import com.example.demo.algorithm.sort.Shell;

import java.io.*;
import java.util.ArrayList;

/**
 * @Author: xiatian
 * @CreateTime: 2021/9/10 1:59 下午
 * @Description:
 */
public class SortCompare {
    public static void main(String[] args) throws Exception {
        ArrayList<Integer> list = new ArrayList<Integer>();
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("src/main/resources/static/reverse_arr.txt"))));
        String line = null;
        while (null != (line = br.readLine())) {
            list.add(Integer.parseInt(line));
        }
        br.close();
        //把集合转换成数组
        Integer[] a = new Integer[list.size()];
        list.toArray(a);
       // testInsertion(a);//31558毫秒
        testShell(a); //30毫秒
    }

    public static void testInsertion(Integer[] a) {
        long start = System.currentTimeMillis();
        Insertion.sort(a);
        long end = System.currentTimeMillis();
        System.out.println("插入排序耗时：" + (end - start) + "毫秒");
    }

    public static void testShell(Integer[] a) {
        long start = System.currentTimeMillis();
        Shell.sort(a);
        long end = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (end - start) + "毫秒");
    }

}
